home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / ps40sdk / examples / export / history / common / history.c next >
Encoding:
C/C++ Source or Header  |  1996-09-30  |  4.0 KB  |  195 lines

  1. /*
  2.     File: History.c
  3.  
  4.     Copyright (c) 1990, Thomas Knoll.
  5.     Copyright (c) 1993-6, Adobe Systems Incorporated.
  6.     All rights reserved.
  7.  
  8.     C source file for History export example.
  9. */
  10.  
  11. #if __MWERKS__
  12. #include <SetupA4.h> // A4-globals
  13. #include <A4Stuff.h> // A4-globals
  14. #endif
  15.  
  16. #if defined(THINK_C) || defined(__MWERKS__)
  17. #define ENTRYPOINT main
  18. #endif
  19.  
  20. #include "History.h"
  21.  
  22. Handle hDllInstance = NULL;
  23.  
  24. /*****************************************************************************/
  25.  
  26. void InitGlobals (GPtr globals);
  27. void DoAbout (GPtr globals);
  28. void DoPrepare (GPtr globals);
  29. void DoStart (GPtr globals);
  30. void DoContinue (GPtr globals);
  31. void DoFinish (GPtr globals);
  32.  
  33. /*****************************************************************************/
  34.  
  35. /* All calls to the plug-in module come through this routine. It must be
  36.    placed first in the resource. To achieve this, most development systems
  37.    require that this be the first routine in the source. */
  38.  
  39. #if MSWindows
  40.        void ENTRYPOINT (short selector,
  41.                         ExportRecord *exportParamBlock,
  42.                         long *data,
  43.                         short *result)                
  44. #else
  45. pascal void ENTRYPOINT (short selector,
  46.                         ExportRecord *exportParamBlock,
  47.                         long *data,
  48.                         short *result)                
  49. #endif
  50. {
  51.     
  52.     Globals globalValues;
  53.     GPtr globals = &globalValues;
  54.     
  55.     #if __MWERKS__
  56.     EnterCodeResource(); // A4-globals
  57.     #endif
  58.     
  59.     if (!*data)
  60.         {
  61.         
  62.         InitGlobals (globals);
  63.  
  64.         *data = (long) NewHandle (sizeof (Globals));
  65.         
  66.         if (!*data)
  67.             {
  68.             *result = memFullErr;
  69.             return;
  70.             }
  71.             
  72.         ** (GHdl) *data = globalValues;
  73.         
  74.         }
  75.         
  76.     globalValues = ** (GHdl) *data;
  77.         
  78.     gStuff = exportParamBlock;
  79.     gResult = noErr;
  80.         
  81.     switch (selector)
  82.         {
  83.         
  84.         case exportSelectorAbout:
  85.             DoAbout (globals);
  86.             break;
  87.             
  88.         case exportSelectorPrepare:
  89.             DoPrepare (globals);
  90.             break;
  91.         
  92.         case exportSelectorStart:
  93.             DoStart (globals);
  94.             break;
  95.         
  96.         case exportSelectorContinue:
  97.             DoContinue (globals);
  98.             break;
  99.         
  100.         case exportSelectorFinish:
  101.             DoFinish (globals);
  102.             break;
  103.             
  104.         default:
  105.             gResult = exportBadParameters;        
  106.         }
  107.         
  108.     *result = gResult;
  109.     ** (GHdl) *data = globalValues;
  110.  
  111.     #if __MWERKS__
  112.     ExitCodeResource(); // A4-globals
  113.     #endif
  114.     
  115. }
  116.  
  117. /*****************************************************************************/
  118.  
  119. void InitGlobals (GPtr globals)
  120. {
  121.     gCurrentHistory = 1;
  122. }
  123.  
  124. /*****************************************************************************/
  125.  
  126. /* Prepare to export an image.    If the plug-in module needs only a limited
  127.    amount of memory, it can lower the value of the 'maxData' field. */
  128.  
  129. void DoPrepare (GPtr globals)
  130.     {
  131.     
  132.     gStuff->maxData = 0;
  133.     
  134.     }
  135.  
  136. /*****************************************************************************/
  137.  
  138. void GetHistory (GPtr globals, int16 index, Str255 s)
  139. {    
  140.     int16 currentResources = CountPIResources(histResource);
  141.     
  142.     s[ (s[0]=0) + 1] = 0;
  143.     
  144.     if (currentResources >= index)
  145.     {
  146.         Handle h = GetPIResource (histResource, index);    
  147.         if (h != NULL) PIHandle2String(h, s);
  148.         // just a read-only reference.  Do NOT dispose.
  149.     }
  150. }
  151.  
  152. /*****************************************************************************/
  153.  
  154. /* Requests pointer to the first part of the image to be filtered. */
  155.  
  156. void DoStart (GPtr globals)
  157. {
  158.     short doThis = true;
  159.     
  160.     if (!WarnResourceProcsAvailable ())
  161.     {
  162.         gResult = errPlugInHostInsufficient;
  163.         return;
  164.     }
  165.         
  166.     gQueryForParameters = ReadScriptParams (globals);
  167.     
  168.     if ( gQueryForParameters ) doThis = DoParameters (globals);
  169.     
  170.     if ( doThis == false ) ; // user cancelled, etc.
  171.  
  172. }
  173.  
  174. /*****************************************************************************/
  175.  
  176. /* Filters the area and requests the next area. */
  177.  
  178. void DoContinue (GPtr globals)
  179. {
  180. }
  181.  
  182. /*****************************************************************************/
  183.  
  184. /* This routine will always be called if DoStart does not return an error
  185.    (even if DoContinue returns an error or the user aborts the operation).
  186.    This allows the module to perform any needed cleanup.  None is required
  187.    in this example. */
  188.  
  189. void DoFinish (GPtr globals)
  190. {
  191.     WriteScriptParams(globals);
  192. }
  193.  
  194. /*****************************************************************************/
  195.